﻿Imports Configuration.Templating.Context

Namespace Configuration.Templating.Default

    Public Class DefaultTemplateProvider
        Implements IDefaultTemplateProvider

        Private HT As New Dictionary(Of String, String)

        Private Shared ReadOnly DefaultResultItemTemplateValue As String = _
            "<div class=""item"" align=""left"">" & vbCrLf & _
            "    <h3>" & vbCrLf & _
            "        <a class=""title"" href=""[Result:GoToUrl]"">" & vbCrLf & _
            "            [Result:Title]</a></h3>" & vbCrLf & _
            "    <div class=""content"">" & vbCrLf & _
            "        [Result:Description]</div>" & vbCrLf & _
            "    <br />" & vbCrLf & _
            "    <div class=""highlights"">" & vbCrLf & _
            "        [Result:Highlights]</div>" & vbCrLf & _
            "    <div class=""infos"">" & vbCrLf & _
            "        <span>[Result:FriendlyModuleName] from [Result:AuthorName|{0}|Unspecified author]," & vbCrLf & _
            "        </span>" & vbCrLf & _
            "        <br />" & vbCrLf & _
            "        <span>published [Result:PubDate|dd MMMM yyyy], indexed [Result:IndexedDate|dd MMMM yyyy]</span><br />" & vbCrLf & _
            "        <cite>[Result:GoToFullUrl]</cite></div>" & vbCrLf & _
            "</div>"

        Private Shared ReadOnly DefaultGridItemTemplateValue As String = _
            "[Result:Relevance]" & vbCrLf & _
            "[Result:GoToUrl]" & vbCrLf & _
            "[Result:Title]" & vbCrLf & _
            "[Result:Description]" & vbCrLf & _
            "[Result:Highlights]"

        Private Shared ReadOnly DefaultDetailsItemTemplateValue As String = _
            "<div class=""item"" align=""left"">" & vbCrLf & _
            "    <h3>" & vbCrLf & _
            "        <span class=""SubHead"">[Result:Relevance]% </span><a class=""title"" href=""[Result:GoToUrl]"">" & vbCrLf & _
            "            [Result:Title]</a></h3>" & vbCrLf & _
            "    <div class=""content"">" & vbCrLf & _
            "        [Result:Description]</div>" & vbCrLf & _
            "    <br />" & vbCrLf & _
            "    <div class=""highlights"">" & vbCrLf & _
            "        [Result:Highlights]</div>" & vbCrLf & _
            "    <div class=""infos"">" & vbCrLf & _
            "        <span>[Result:FriendlyModuleName] from [Result:AuthorName|{0}|Unspecified author]," & vbCrLf & _
            "        </span>" & vbCrLf & _
            "        <br />" & vbCrLf & _
            "        <span>published [Result:PubDate|dd MMMM yyyy], indexed [Result:IndexedDate|dd MMMM yyyy]</span><br />" & vbCrLf & _
            "        <cite>[Result:GoToFullUrl]</cite></div>" & vbCrLf & _
            "</div>"

        Public Sub New()
            HT.Add(TemplateTypes.Template.ToString(), DefaultResultItemTemplateValue)
            HT.Add(TemplateTypes.Grid.ToString(), DefaultGridItemTemplateValue)
            HT.Add(TemplateTypes.Details.ToString(), DefaultDetailsItemTemplateValue)
        End Sub

        Public Function GetDefaultTemplate(key As String) As String Implements IDefaultTemplateProvider.GetDefaultTemplate
            If (HT.ContainsKey(key)) Then
                Return HT(key)
            End If
            Return "undefined"
        End Function
    End Class

End Namespace